package com.hui.platform.falseworkapi.common.mybatis;

import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 	Mybatis全局配置类
 * @author hui
 *
 */
@Configuration
@MapperScan({
        "com.hui.platform.falseworkapi.service.business.*.mapper"
})
@EnableConfigurationProperties(MybatisPlusProperties.class)
public class MybatisPlusConfiguration {

    /**
     * SQL执行效率插件
     */
    @Bean
    @ConditionalOnProperty(prefix = "falsework.mybatis", name = "debug", havingValue = "true")
    public PerformanceInterceptor performanceInterceptor() {
        PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
        //设置输出格式化输出SQL语句
        performanceInterceptor.setFormat(true);
        //logger日志输出
        performanceInterceptor.setWriteInLog(true);
        return performanceInterceptor;
    }

    /**
     * 分页插件
     */
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        return new PaginationInterceptor();
    }
}
